package cn.lichenes.repository;

import cn.lichenes.entity.Phone;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface PhoneRepository extends JpaRepository<Phone,Integer>,JpaSpecificationExecutor<Phone>{

     List<Phone> findByPhoneBrandPbId(Integer id, Pageable pageable);

     @Query(value = "SELECT pb.pb_name, SUM(p.p_residue) residue,SUM(p.p_sales) sales,SUM(p.p_price * p.p_sales) money FROM phone p,phone_brand pb WHERE p.p_brand = pb.pb_id GROUP BY pb.pb_name",nativeQuery = true)
     List<Map<String,Object>> getEcharts();
}
